import os
ipaddress = 'http://192.168.43.126:5000/'
ipaddress = 'http://192.168.0.114:5000/'
imgUrl = ipaddress + 'img?'
eventImgUrl = ipaddress + 'event/img?'
basedir = os.path.abspath(os.path.dirname(__file__))


def to_id_name(obj, role):
    dic = {}
    dic['ID'] = obj.ID
    dic['name'] = obj.name
    dic['role'] = role
    return dic


def eventToDict(event, oldperson_name):
    dic = {}
    dic['ID'] = event.ID
    dic['event_type'] = event.event_type
    dic['event_date'] = str(event.event_date)
    dic['event_desc'] = event.event_desc
    dic['event_location'] = event.event_location
    dic['oldperson_id'] = event.oldperson_id
    dic['oldperson_name'] = oldperson_name
    dic['img'] = eventImgUrl+'dir=' + basedir + '/' + event.images_path
    return dic


def OldToDict(old):
    dic = {}
    dic['ID'] = old.ID
    dic['name'] = old.name
    dic['age'] = old.age
    dic['gender'] = old.gender
    dic['phone'] = old.phone
    dic['room_number'] = old.room_number
    # dic['checkin_date'] = str(old.checkin_date)
    # dic['checkout_date'] = str(old.checkout_date)
    dic['remove'] = old.remove
    dic['description'] = old.description
    dic['health_state'] = old.health_state
    dic['img'] = imgUrl+'role=old&ID='+ str(old.ID)
    return dic


def dictToOldDic(data):
    oldDic = {}
    oldDic['ID'] = data['ID']
    oldDic['name'] = data['name']
    oldDic['age'] = data['age']
    oldDic['gender'] = data['gender']
    oldDic['phone'] = data['phone']
    oldDic['room_number'] = data['room_number']
    # oldDic['checkin_date'] = data['checkin_date']
    # oldDic['checkout_date'] = data['checkout_date']
    oldDic['remove'] = data['remove']
    oldDic['description'] = data['description']
    oldDic['health_state'] = data['health_state']
    return oldDic


def volToDict(volunteer):
    dic = {}
    dic['ID'] = volunteer.ID
    dic['name'] = volunteer.name
    dic['age'] = volunteer.age
    dic['gender'] = volunteer.gender
    dic['phone'] = volunteer.phone
    dic['remove'] = volunteer.remove
    dic['description'] = volunteer.description
    dic['email'] = volunteer.email
    dic['address'] = volunteer.address
    dic['img'] = imgUrl + 'role=vol&ID=' + str(volunteer.ID)
    return dic


def dictToVolDic(data):
    volunteerDic = {}
    volunteerDic['ID'] = data['ID']
    volunteerDic['name'] = data['name']
    volunteerDic['age'] = data['age']
    volunteerDic['gender'] = data['gender']
    volunteerDic['phone'] = data['phone']
    volunteerDic['email'] = data['email']
    volunteerDic['remove'] = data['remove']
    volunteerDic['address'] = data['address']
    volunteerDic['description'] = data['description']
    return volunteerDic


def adminToDict(admin):
    dic = {}
    dic['ID'] = admin.ID
    dic['name'] = admin.name
    dic['password'] = admin.password
    dic['age'] = admin.age
    dic['gender'] = admin.gender
    dic['phone'] = admin.phone
    dic['remove'] = int(admin.remove)
    dic['description'] = admin.description
    # dic['profile_photo'] = admin.profile_photo
    dic['img'] = imgUrl + 'role=admin&ID=' + str(admin.ID)
    dic['email'] = admin.email
    return dic


def dictToAdminDic(data):
    adminDic = {}
    adminDic['ID'] = data['ID']
    adminDic['name'] = data['name']
    adminDic['password'] = data['password']
    adminDic['age'] = data['age']
    adminDic['gender'] = data['gender']
    adminDic['phone'] = data['phone']
    adminDic['remove'] = data['remove']
    adminDic['email'] = data['email']
    adminDic['description'] = data['description']
    return adminDic


